package com.zzty.taskapp.serviceImpl;

import com.zzty.taskapp.dao.ClassDAO;
import com.zzty.taskapp.dao.UserDAO;
import com.zzty.taskapp.daoImpl.ClassDAOImpl;
import com.zzty.taskapp.daoImpl.TeamExamDAOImpl;
import com.zzty.taskapp.daoImpl.UserDAOImpl;
import com.zzty.taskapp.entity.TeamExam;
import com.zzty.taskapp.entity.User;
import com.zzty.taskapp.service.TeamExamService;

public class TeamExamServiceImpl implements TeamExamService {
	TeamExamDAOImpl tx = new TeamExamDAOImpl();
	UserDAO ud = new UserDAOImpl();
	ClassDAO cd = new ClassDAOImpl();

	public String[] getQuestionID(String date, int classid) {

		String rs = tx.getQuestionIDInSQL(date, classid);
		String[] array = rs.split("\\|");
		return array;

	}
	//
	// public String getQuestion(String[] array) {
	// String questions = "";
	// for (int i = 0; i < array.length; i++) {
	// questions = questions + tx.getQuestionInSQL(array[i]);
	// }
	// return questions;
	// }

	public int searchExamId(String date, int classid) {
		int examId = tx.searchExamid(date, classid);
		return examId;
	}

	public int searchClassid(String name) {
		try {
			User u1 = ud.findAllByName(name);
			String clazz = u1.getClasses();
			int classid = Integer.parseInt(clazz);
			return classid;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}

	public int addTeamExam(TeamExam te) {
		return tx.addTeamExam(te);
	}

	public void updateWinners(int examId, String winnerIds , String winnerIds2){
		tx.updateWinnerIds(examId, winnerIds, winnerIds2);
	}

}
